﻿namespace Numbrella.Client
{
	using System;
	using System.ComponentModel;

	internal class CurrentProblemInformationProvider : INotifyPropertyChanged
	{
		public CurrentProblemInformationProvider()
		{
			TaskSolvingEngine.Instance.CurrentProblemChanged += this.OnTaskSolvingEngineCurrentProblemChanged;
		}

		public event PropertyChangedEventHandler PropertyChanged;

		public string ProblemName
		{
			get
			{
				return TaskSolvingEngine.Instance.CurrentProblemDefinition == null
						? String.Empty
						: TaskSolvingEngine.Instance.CurrentProblemDefinition.Name;
			}
		}

		public string ProblemDescriptionText
		{
			get
			{
				return TaskSolvingEngine.Instance.CurrentProblemDefinition == null
						? String.Empty
						: TaskSolvingEngine.Instance.CurrentProblemDefinition.Description.Text;
			}
		}

		private void OnTaskSolvingEngineCurrentProblemChanged(object sender, EventArgs e)
		{
			this.RaisePropertyChanged(new PropertyChangedEventArgs("ProblemName"));
			this.RaisePropertyChanged(new PropertyChangedEventArgs("ProblemDescriptionText"));
		}

		private void RaisePropertyChanged(PropertyChangedEventArgs e)
		{
			PropertyChangedEventHandler handler = this.PropertyChanged;
			if (handler != null)
				handler(this, e);
		}
	}
}
